package com.example.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.example.business.entity.SysConfig;
import com.example.business.mapper.SysConfigMapper;
import com.example.business.service.SysConfigService;
import org.springframework.cache.annotation.*;
import java.io.Serializable;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.cache.annotation.CacheConfig;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiong
 * @since 2024-01-26
 */
@Service
@Transactional
@CacheConfig(cacheNames = "SysConfigServiceImpl")
public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements SysConfigService {

    @Cacheable(cacheNames = "sysconfig",key = "#id")
    @Override
    public SysConfig getById(Serializable id){
        return super.getById(id);
    }

    @CacheEvict(cacheNames = "sysconfig", key = "#id")
    @Override
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }

    @CacheEvict(cacheNames = "sysconfig", key = "#sysconfig.id")
    @Override
    public boolean updateById(SysConfig sysconfig) {
        return super.updateById(sysconfig);
    }

    @CachePut(cacheNames = "sysconfig", key = "#sysconfig.id")
    public SysConfig saveSysConfig(SysConfig sysconfig){
        super.save(sysconfig);
        return sysconfig;
    }

    @CacheEvict(cacheNames = "sysconfig", key = "#sysconfig.id")
    public SysConfig updateSysConfigById(SysConfig sysconfig){
        super.updateById(sysconfig);
        return sysconfig;
    }

    @Cacheable(cacheNames = "sysconfig",key = "#key")
    @Override
    public SysConfig getSysConfigByKey(String key) {
        LambdaQueryWrapper<SysConfig> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SysConfig::getSysKey,key);
        SysConfig sysConfig=this.baseMapper.selectOne(lambdaQueryWrapper);
        return sysConfig;
    }
}
